package net.lesscoding.controller;

import cn.hutool.core.lang.hash.Hash;
import cn.hutool.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @author eleven
 * @date 2023/2/22 15:28
 * @description
 */
@RestController
@Slf4j
public class TestController {

    @GetMapping("/test")
    public Object test() {
        log.info("{} -- 调用接口成功", System.currentTimeMillis());
        return Collections.singletonMap("success", "true");
    }

    @GetMapping("/run")
    public Object run(){
        int success = 0;
        int failed = 0;
        for (int i = 0; i < 1000; i++) {
            try {
                Thread.sleep(20);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            String body = HttpUtil.get("http://localhost:8080/test");
            if (body.contains("success")) {
                success++;
            }else {
                failed++;
            }
        }
        log.info("成功次数<===>{},失败次数<===>{}",success,failed);
        Map<String,Integer> map = new HashMap<>(2);
        map.put("success", success);
        map.put("failed", failed);
        return map;
    }
}
